package notes.java.sjms23.t10_visitor;

// 具体访问者，计算面积
public class VisitorArea implements Visitor{

    @Override
    public double ofShap(ShapeTriangle triangle) {
        // 三角形面积
        double a = triangle.getA();
        double b = triangle.getB();
        double c = triangle.getC();
        double p = (a + b + c)/2;
        double area = Math.sqrt(p * (p-a) * (p-b) * (p-c));
        System.out.println("圆形面积：" + area);
        return area;
    }

    @Override
    public double ofShap(ShapeSquare square) {
        // 长方形面积
        double area = square.getA() * square.getB();
        System.out.println("长方形面积：" + area);
        return area;
    }

    @Override
    public double ofShap(ShapeCircle circle) {
        // 圆形面积
        double area = Math.PI*circle.getR()*circle.getR();
        System.out.println("圆形面积：" + area);
        return area;
    }

}
